﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Carbon.Web.Forms.Extensions;

namespace Carbon.Web.Forms.Controls
{
    public class DataContextOnPath : System.Web.UI.Control, IDataProxy
    {
        private String m_DataPath = default(String);
        public String DataPath
        {
            get
            {
                return m_DataPath;
            }
            set
            {
                m_DataPath = value;
            }
        } 
       
        public object DataContext
        {
            get 
            {
                if (string.IsNullOrEmpty(DataPath)) throw new ArgumentOutOfRangeException("DataPath");

                Object parentContext = this.GetViewModelContext();

                Binder binder = new Binder(parentContext, DataPath, true);

                return binder.Value;
            }
        }
    }
}
